'use strict';

import Vue from 'vue'
import util from '@/util/Util'
import qs from 'qs'

const _vue = new Vue()

const _live = {
	// 获取直播信息
	'getLiveInfo': function(param) {
		let queryStr = '?page_number=' + param.page_number +
			'&page_size=' + param.page_size;
		if(param.is_live) {
			queryStr += '&is_live=' + param.is_live;
		}
		if(param.user_id) {
			queryStr += '&user_id=' + param.user_id;
		}
		return _vue.$axios.get(util.getServerUrl('/live/getLiveInfo') + queryStr)
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
	// 更新直播信息
	'updateLiveInfo': function(param) {
		return _vue.$axios.post(util.getServerUrl('/live/updateLiveInfo'), {
				'user_id': param.user_id,
				'name': param.name,
				'title': param.title,
				'room_id': param.room_id,
				'cover': param.cover,
				'viewing_number': param.viewing_number,
				'is_live': param.is_live,
				'category_id': param.category_id
			})
			.then(function(response) {
				if(param.success) {
					param.success(response)
				}
				return response
			})
			.catch(function(error) {
				console.log(error)
			})
	},
}

export default _live